import React, { useState } from 'react';
import { Flex, Table } from 'antd';
import type { TableProps } from 'antd';

type TableRowSelection<T extends object = object> = TableProps<T>['rowSelection'];
interface SickbedTabProps {
    columns: any[];
    dataSource: any[];
    pagination?: { current?: number; pageSize?: number };
  }
function SickbedTab(props: SickbedTabProps) {
    const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
    
    const onSelectChange = (newSelectedRowKeys: React.Key[]) => {
        console.log('selectedRowKeys changed: ', newSelectedRowKeys);
        localStorage.setItem('newSelectedRowKeys',JSON.stringify(newSelectedRowKeys))
        setSelectedRowKeys(newSelectedRowKeys);
    };

    const rowSelection: TableRowSelection = {
        selectedRowKeys,
        onChange: onSelectChange,
    };
    return (
        <div style={{border:'1px solid #ccc'}}>
            <Flex gap="middle" vertical>
                <Table pagination={props.pagination} rowSelection={rowSelection} columns={props.columns} dataSource={props.dataSource} />
            </Flex>
        </div>
    );
}

export default SickbedTab;